<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .login-container {
            background: rgba(255, 255, 255, 0.95);
            padding: 40px;
            border-radius: 20px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
            width: 100%;
            max-width: 400px;
            backdrop-filter: blur(10px);
            transform: translateY(0);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        .login-container:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
        }

        h2 {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
            font-size: 28px;
            font-weight: 600;
        }

        .form-group {
            margin-bottom: 25px;
            position: relative;
        }

        .form-group i {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #764ba2;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: 500;
        }

        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 15px 15px 15px 45px;
            border: 2px solid #e1e1e1;
            border-radius: 10px;
            font-size: 16px;
            transition: all 0.3s ease;
            outline: none;
        }

        input[type="text"]:focus, input[type="password"]:focus {
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
        }

        .btn {
            width: 100%;
            padding: 15px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 10px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 600;
            transition: all 0.3s ease;
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(102, 126, 234, 0.6);
        }

        .btn:active {
            transform: translateY(0);
        }

        .flash-messages {
            margin-bottom: 20px;
        }

        .flash-message {
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 15px;
            text-align: center;
            font-weight: 500;
            animation: slideIn 0.3s ease;
        }

        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateX(-20px);
            }
            to {
                opacity: 1;
                transform: translateX(0);
            }
        }

        .flash-message.success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .flash-message.error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        .flash-message.info {
            background-color: #d1ecf1;
            color: #0c5460;
            border: 1px solid #bee5eb;
        }

        .app-title {
            text-align: center;
            margin-bottom: 30px;
        }

        .app-title h1 {
            color: white;
            font-size: 32px;
            text-shadow: 0 2px 4px rgba(0,0,0,0.3);
        }

        .app-title p {
            color: rgba(255, 255, 255, 0.9);
            font-size: 16px;
            margin-top: 10px;
        }

        /* 登录方式切换 */
        .login-methods {
            display: flex;
            margin-bottom: 25px;
            border-bottom: 2px solid #eee;
        }

        .method-btn {
            flex: 1;
            padding: 12px;
            text-align: center;
            background: none;
            border: none;
            font-weight: 600;
            color: #999;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .method-btn.active {
            color: #667eea;
            border-bottom: 3px solid #667eea;
        }

        .login-form {
            display: none;
        }

        .login-form.active {
            display: block;
        }

        /* 验证码相关样式 */
        .code-group {
            position: relative;
        }

        .send-code-btn {
            position: absolute;
            right: 5px;
            top: 50%;
            transform: translateY(-50%);
            background: #667eea;
            color: white;
            border: none;
            border-radius: 5px;
            padding: 8px 12px;
            cursor: pointer;
            font-size: 14px;
            transition: background 0.3s;
        }

        .send-code-btn:hover {
            background: #5a6fd8;
        }

        .send-code-btn:disabled {
            background: #ccc;
            cursor: not-allowed;
        }

        @media (max-width: 480px) {
            .login-container {
                padding: 30px 20px;
            }
            
            .app-title h1 {
                font-size: 24px;
            }
        }
    </style>
</head>
<body>
    <div class="app-title">
        <h1>欢迎使用系统</h1>
        <p>请登录以继续访问</p>
    </div>
    
    <div class="login-container">
        <h2><i class="fas fa-lock"></i> 用户登录</h2>
        
        <!-- 登录方式切换 -->
        <div class="login-methods">
            <button class="method-btn active" data-method="username">账号登录</button>
            <button class="method-btn" data-method="phone">手机登录</button>
        </div>
        
        <div class="flash-messages">
            {% with messages = get_flashed_messages(with_categories=true) %}
                {% if messages %}
                    {% for category, message in messages %}
                        <div class="flash-message {{ category }}">{{ message }}</div>
                    {% endfor %}
                {% endif %}
            {% endwith %}
        </div>
        
        <!-- 用户名密码登录表单 -->
        <form id="username-login" class="login-form active" method="POST">
            <input type="hidden" name="login_type" value="username">
            <div class="form-group">
                <label for="username">用户名:</label>
                <i class="fas fa-user"></i>
                <input type="text" id="username" name="username" placeholder="请输入用户名" required>
            </div>
            
            <div class="form-group">
                <label for="password">密码:</label>
                <i class="fas fa-key"></i>
                <input type="password" id="password" name="password" placeholder="请输入密码" required>
            </div>
            
            <button type="submit" class="btn">登录系统</button>
        </form>
        
        <!-- 手机号验证码登录表单 -->
        <form id="phone-login" class="login-form" method="POST">
            <input type="hidden" name="login_type" value="phone">
            <div class="form-group">
                <label for="phone">手机号:</label>
                <i class="fas fa-mobile-alt"></i>
                <input type="text" id="phone" name="phone" placeholder="请输入手机号" required pattern="1[0-9]{10}" maxlength="11">
            </div>
            
            <div class="form-group code-group">
                <label for="code">验证码:</label>
                <i class="fas fa-lock"></i>
                <input type="text" id="code" name="code" placeholder="请输入验证码" required pattern="[0-9]{6}" maxlength="6">
                <button type="button" class="send-code-btn" id="send-code">发送验证码</button>
            </div>
            
            <button type="submit" class="btn">登录系统</button>
        </form>
    </div>

    <script>
        // 登录方式切换
        const methodButtons = document.querySelectorAll('.method-btn');
        const loginForms = document.querySelectorAll('.login-form');
        
        methodButtons.forEach(button => {
            button.addEventListener('click', () => {
                const method = button.dataset.method;
                
                // 更新按钮状态
                methodButtons.forEach(btn => btn.classList.remove('active'));
                button.classList.add('active');
                
                // 显示对应的表单
                loginForms.forEach(form => {
                    form.classList.remove('active');
                    if (form.id === method + '-login') {
                        form.classList.add('active');
                    }
                });
            });
        });
        
        // 发送验证码功能
        const sendCodeBtn = document.getElementById('send-code');
        let countdown = 60;
        let countdownTimer = null;
        
        sendCodeBtn.addEventListener('click', () => {
            const phoneInput = document.getElementById('phone');
            const phone = phoneInput.value.trim();
            
            if (!phone) {
                alert('请输入手机号');
                return;
            }
            
            if (!/^1[0-9]{10}$/.test(phone)) {
                alert('手机号格式不正确');
                return;
            }
            
            // 发送验证码请求
            fetch('/send_code', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: 'phone=' + encodeURIComponent(phone)
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('验证码已发送，请注意查收');
                    startCountdown();
                } else {
                    alert(data.message);
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('发送验证码失败，请重试');
            });
        });
        
        function startCountdown() {
            sendCodeBtn.disabled = true;
            sendCodeBtn.textContent = countdown + '秒后重发';
            
            countdownTimer = setInterval(() => {
                countdown--;
                sendCodeBtn.textContent = countdown + '秒后重发';
                
                if (countdown <= 0) {
                    clearInterval(countdownTimer);
                    sendCodeBtn.disabled = false;
                    sendCodeBtn.textContent = '发送验证码';
                    countdown = 60;
                }
            }, 1000);
        }
    </script>
</body>
</html>